﻿/// <reference path="jquery-1.5.1-vsdoc.js" />

////////////////////// ////////// HGO Label Start Code ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

(function ($) {

  var $t = $.telerik;

  $t.hgolabel = function (element, options) {
    if (element.nodeName.toLowerCase() !== "label") {
      throw "Target element is not a LABEL";
    }

    $.extend(this, options);

    this.element = element;
    var $element = this.$element = $(element);

    var builder = new $t.stringBuilder();

    if (element.parentNode.nodeName.toLowerCase() !== "div") {
      $element.wrap($('<div class="t-widget t-hgotextbox"></div>'));
    }

    if ((element.nextSibling == null) || (element.nextSibling.nodeName.toLowerCase() !== "span")) {
      builder.buffer = [];

      if (this.requiredField) {
        builder.cat('<span class="t-hgolabel t-span" style="color:red">');
        builder.cat('*')
        builder.cat('</span>');
      }

      if (this.warningField) {
        builder.cat('<span class="t-hgolabel t-span" style="color:blue">');
        builder.cat('*')
        builder.cat('</span>');
      }

      if (builder.buffer.length > 0) {
        $(builder.string()).insertAfter($element);
      }
    }

    this.$wrapper = $element.closest('.t-hgolabel');

    this[this.enabled ? 'enable' : 'disable']();
  }

  $t.hgolabel.prototype =
  {
    _keydown: function (e) {
      return true;
    },

    _keypress: function (e) {
      return true;
    },

    hide: function () {
      var wrapper = this.$wrapper;
      wrapper.hide();
    },

    show: function () {
      var wrapper = this.$wrapper;
      wrapper.show();
    },

    _modify: function () {
      this._update(this.$element.text());
    },

    _update: function (text) {
      this._text(val);
    },

    _text: function (value) {
      this.$element.text(value);
    },

    enable: function () 
    {
      this.enabled = true;
      this.$element.css("color", this.enableFontColor);
      this.$wrapper.removeClass('t-state-disabled');
    },

    disable: function () 
    {
      this.enabled = false;
      this.$element.css("color", this.disableFontColor);
      this.$wrapper.addClass('t-state-disabled');
    },

    text: function (textstr) 
    {
      if (typeof(textstr) === 'undefined' || textstr === null) 
        return this.$element.text();

      this._text(textstr);
    }
  }

  $.fn.tHGOLabel = function (options) {
    var type = 'hgolabel';
    var defaults = $.fn.tHGOLabel.defaults[type];
    options = $.extend({}, defaults, options);
    options.type = type;

    return this.each(
                      function () {
                        var $element = $(this);
                        options = $.meta ? $.extend({}, options, $element.data()) : options;

                        if (!$element.data('tHGOLabel')) {
                          $element.data('tHGOLabel', new $t.hgolabel(this, options));
                          $t.trigger(this, 'load');
                        }
                      }
                    );
  };

  var commonDefaults =
  {
    caption: '',
    enabled: true,
    disableFontColor: "#848383",
    enableFontColor: "black",
    requiredField: false,
    warningField: false
  };

  $.fn.tHGOLabel.defaults = {
    hgolabel: $.extend(commonDefaults,
                                      {
                                        prop1: ''
                                      }
                        )
  };

})(jQuery);


//////////////////// HGO Label End Code //////////////////////////////
////////////////////////////////////////////////////////////////////////
///  Örn Disable => $('#HGOLabel').data('tHGOLabel').disable()      ////
///  Örn Enable => $('#HGOLabel').data('tHGOLabel').enable()        ////
///  Örn Hide => $('#HGOLabel').data('tHGOLabel').hide()            ////
///  Örn Show => $('#HGOLabel').data('tHGOLabel').show()            ////
///  Örn SetText => $('#HGOLabel').data('tHGOLabel').text('test')   ////
///  Örn GetText => $('#HGOLabel').data('tHGOLabel').text()         ////
////////////////////////////////////////////////////////////////////////

// Firefox ile test etmek için örnek Label kullanımı...
// $('#HGOLabel').attr('TPCCN', 'tHGOLabel')
// $('#HGOLabel').attr('ELFI', 'test')
// $('#HGOLabel').data('tHGOLabel').text('UserName:')
// document.getLabelCaption('test')
// document.setLabelCaption('test', 'aaaaa')


	
